Forum Moderators: open

Message Too Old, No Replies

help with jQuery/Javascript all in an iFrame needed

         

KansasCoder

6:45 pm on Apr 3, 2009 (gmt 0)

10+ Year Member



I am new to the client-side and appreciate any help you can provide me with this.

I am working on a Windows based intranet. We all use IE 6 and soon IE 7.

I have a page that utlilzes an iFrame. I have added jQuery.js, json.js and some javascript functions to this iFrame. I need to handle the click event of the anchor tags in the iFrame but have so far only gotten the message: 'Object Expected' in IE and in FF Firebug 'anchorLink is not defined'. anchorLink is the name of the function I have defined on the iFrame page.

I have tried to add the js code to the main page and to the iFrame with equal, erroneous, results.

My iFrame headers is:


<head>
<meta http-equiv="Content-Script-Type" content="text/javascript"><script src="../../js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="../../js/json.mini.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
function anchorClick(){alert('hi');}
});// end of ready func -- no jquey scripts below this line
</script>
</head>

The anchor element is defined as:


<a href="#" OnClick="anchorClick" class = "enrollment" style="cursor: hand;" id="4">

I have seen where folks have had issues calling the parent from the iframe and vice versa but in my case everything is in the iFrame.
The html tag and js script elements are all being written via response.write in the vb code..if that matters.
If I have left out any important info please request it. As I mentioned I am new to the client-side of things. Thank you for your time!

[edited by: KansasCoder at 6:57 pm (utc) on April 3, 2009]

KansasCoder

7:21 pm on Apr 3, 2009 (gmt 0)

10+ Year Member



I just commented out the jQuery lines:

$(document).ready(function() {

that was wrapping my javascript and now the alert is firing.

So I guess the issue is with the jQuery library? I need to use jQuery to make an ajax call to a webmethod so its pretty importantt aht I get this to work this way. It is also how we are doing ajax on our site so I'd like to keep things as consistent as possible.

Any ideas why the Jquery would not be working properly inside an iframe? I tried loading it on the parent page and it made no difference.

Thank you

KansasCoder

8:33 pm on Apr 3, 2009 (gmt 0)

10+ Year Member



Still scratching my head on this one. Any ideas as to why this is happening? I verified that the jquery is being pointed to properly in the js directory but for some reason it appears to not getting to the ready state. not sure how to test that.

DrDoc

6:40 pm on Apr 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



a) The event is
onclick
, not
OnClick
. Always use all-lowercase HTML tags and attributes.
b) You need "()" to indicate that a function should be called:
onclick="anchorClick()"

KansasCoder

2:10 pm on Apr 6, 2009 (gmt 0)

10+ Year Member



I removed the function call from the anchor tag. With jQuery it isn't needed. I then used this in my head and all is hunky-dory. Hope this helps anyone else.


<script type="text/javascript">
$(document).ready(function() {
$('#iFrameName').ready( function(){
$("a.enrollment").click(function(){alert('clicked');});
});
});line</script>

There's actually quite a bit online about jQuery and iFrames.