0

I'm working with cordova 3.5

I've an iframe setup as following:

  <iframe src="http://localhost/test/index.html" style="width:100%;height:90%" onLoad="checkforclose(this);"></iframe>

And the JS is the following:

<script type="text/javascript">
function checkforclose(pageURL) { 
    var urlFrame = pageURL.contentWindow.location; //WORKS
    alert(urlFrame); //WORKS
    alert(urlFrame.indexOf('test')); //DOESN'T WORK EVEN FOR ANY VALUE - RETURNS UNDEFINED
}   
</script>   

The snippet works, because the first two lines works. But the third don't. Even more, in JSFiddler works. I'm very lost with this.

Thanks in advance

3
  • 1
    could you provide the jsfiddle link please? Commented Oct 16, 2014 at 20:21
  • yes but it won't work because the iframe is pointing to my localhost Commented Oct 16, 2014 at 20:26
  • jsfiddle.net/7Zy3Q/20 Commented Oct 16, 2014 at 20:28

2 Answers 2

2

Try alert(urlFrame.href.indexOf('test'));

The reason it doesn't work is you are calling indexOf on a window.location (urlFrame) Object. It is throwing an error because indexOf() is not a function property of window.location.

Sign up to request clarification or add additional context in comments.

5 Comments

Sorry, I don't understand you. You mean that: pageURL.contentWindow.location.indexOf doesn't work?
Yes, that is correct. indexOf will only work on Arrays ( >IE8 ) and Strings
Even more, this was a Kobashi Maru to me, so easy for you and hard to solve to me :S I must have think out of the box more often.
I use the Chrome browsers developement tools to debug the JS you wrote. This way I can see errors in the console and set breakpoints to debug the code.
I was blocked in the android emulator :S Bad for me. I'll begin to work as you
0

Try this...

var urlFrame = pageURL.src

You are getting undefined because value of "urlFrame" is empty.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.