Jump to content

Recommended Posts

The code below does not pass the HTML 4.01 Transitional w3c validator. the part that fails validation is the word onload. I have tried moving that onload code to the body of the html. it validates fine but it does not work as it should. the page that loads the iframe has an anchor called tag. when a link is clicked in the iframe, the page that loaded the iframe should scroll up to the html anchor of tag but the code when in the body of the html only fires up once at the initial page load.

 

Another problem is that i can't so easily change doc type to frames because i would then need to change many files that php included the html header. how can i get this code to work with the validator. thank you in advance.

 

<a id="tag"></a>
<iframe src="index.php" onload="this.contentwindow.document.onclick=location.href='#tag'" id="frame" width = "100%" scrolling="no" ></iframe>

Link to comment
https://forums.phpfreaks.com/topic/271231-iframe-onload-does-not-pass-validation/
Share on other sites

this topic is solved :) the code below will validate and scroll up to the anchor of the page that loaded the iframe when the link in the iframe is clicked. the code will also resize the iframes height so that all the content is displayed. I found the resize code on the net and added the anchor code to it. if you are looking for the same code as i was then just put this code in the header and remove the onload or onclick code from within the iframe tag.

 

<script type='text/javascript'>
$(function(){
var iFrames = $("#iframe");
function iResize() {

for (var i = 0, j = iFrames.length; i < j; i++) {
iFrames[i].style.height = iFrames[i].contentwindow.document.body.offsetHeight + 'px';
location.href='#tag'; }
}

if ($.browser.safari || $.browser.opera) {

iFrames.load(function(){
setTimeout(iResize, 0);
});

for (var i = 0, j = iFrames.length; i < j; i++) {
var iSource = iFrames[i].src;
iFrames[i].src = '';
iFrames[i].src = iSource;
}

} else {
iFrames.load(function() {
this.style.height = this.contentwindow.document.body.offsetHeight + 'px';
location.href='#tag';
});
}

});
</script>

Edited by kalster
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.