Load javascript in html within content pane

I have an html file that I want to be loaded from various pages into a dijit.contentpane. The content loads fine (I just set the href of the contentpane), but the problem is that javascript within the html file specified by href doesn’t seem to be executed at a consistent time.The final goal of this is to …

via HTML Language Development » Search Results » ajax:

Load javascript in html within content pane

I have an html file that I want to be loaded from various pages into a dijit.contentpane. The content loads fine (I just set the href of the contentpane), but the problem is that javascript within the html file specified by href doesn’t seem to be executed at a consistent time.
The final goal of this is to load an html file into a contentpane at an anchor point in the file (i.e. if you typed in index.html#tag in order to jump to a certain part of the file). I’ve tried a few different methods and can’t seem to get anything to work.
What I’ve tried:
1. (refering to the href of the dijit.contentpane)
href=”page.htm#anchor”2. (again, refering to the href of the dijit.contentpane — didn’t really expect this to work, but decided to try anyways)
href=”#anchor”3. (with this last try inside the html specified by href)
This last try was the closest to working of all of them. After 2 seconds (I put the delay there to see if something in the dijit code was possibly loading at the same time as my javascript), I could see the browser briefly jump to the correct place in the html page, but then immediately go back to the top of the page.
……………………………………….

Dojo uses hashes in the URL to allow bookmarking of pages loaded through ajax calls. This is done through the dojo.hash api. So… I think the best thing you can do is use it to trigger a callback that you write inside your main page.
For scrolling to a given position in your loaded contents, you can then use node.scrollIntoView().
For example, say you have a page with a ContentPane named “mainPane” in which you load an html fragment called “fragment.html”, and your fragment contains 2 anchors like this :
-fragment.html :
Anchor 1

some very long contents…

Anchor 2

some very long contents…

Now say you have 2 buttons in the main page (named btn1 and btn2), which will be used to load your fragment and navigate to the proper anchor. You can then wire that up with the following javascript, in your main page :

……………………………………….

If the content you’re loading contains javascript you should use dojox.layout.ContentPane.

For more info: Load javascript in html within content pane

HTML Language Development » Search Results » ajax

Load javascript in html within content pane

Share this post:

Related Posts

Leave a Comment