The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. February 12, 2012, 08:13:30 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Include JS file from an external JS file...  (Read 2771 times)
nutballs
Administrator
Lifer
*****
Online Online

Posts: 5604


Back in my day we had 9 planets


View Profile
« on: August 23, 2009, 11:22:18 AM »

Obviously I am missing something here.
I am trying to create a widget type of app, so all i want the site owner to have to do is drop 1 line of code (for now no params) into their HTML. So for example below.

I have an HTML page with this in the body:
<script type="text/javascript" src="http://mydomain.com/dev/calendar/cal.php"></script>

in the cal.php I have
Code:
<?php 
$buf 
= <<<BUF
document.write("<script type=\"text/javascript\" src=\"http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js\"></script>");

$(document).ready(function(){
alert('aaa');
});
BUF;
echo 
$buf;
?>


if I monitor the headers, I can see the browser pull down the jquery library, no problem. but the .ready event never fires, and i think its because it has already happened. THe page is already done, THEN the jquery library is pulled down?

so without a .ready event available wtf do i do here to get my code to run. in this case just a simple alert box.

Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 9792



View Profile
« Reply #1 on: August 23, 2009, 11:25:52 AM »

Set a timeout. I believe you're right, the ready event would have fired when the page was completely parsed and up, no? I don't believe that writing to the document would re-trigger that event.

Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Online Online

Posts: 5604


Back in my day we had 9 planets


View Profile
« Reply #2 on: August 23, 2009, 11:43:06 AM »

bah its the stupid timing. I gotta do a timeout it seems.

though I think i will instead loop until i detect the jquery lib being available.

Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« Reply #3 on: May 15, 2010, 04:12:31 PM »


if I monitor the headers, I can see the browser pull down the jquery library, no problem.

Curious how are you monitoring those headers?
Logged

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
nutballs
Administrator
Lifer
*****
Online Online

Posts: 5604


Back in my day we had 9 planets


View Profile
« Reply #4 on: May 15, 2010, 04:39:05 PM »

i used Live HTTP headers probably
https://addons.mozilla.org/en-US/firefox/addon/3829/

but there are a bunch of http sniffer/snooper/watcher tools.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« Reply #5 on: May 15, 2010, 08:10:26 PM »

though I think i will instead loop until i detect the jquery lib being available.

when looping, how did you determine that the lib had become available?
« Last Edit: May 15, 2010, 09:28:44 PM by jammaster82 » Logged

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 9792



View Profile
« Reply #6 on: May 15, 2010, 11:02:00 PM »

You can ask JavaScript if a function exists. If not, it's not loaded yet.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Phaėton
Lifer
*****
Offline Offline

Posts: 503


⎝⏠⏝⏠⎠


View Profile
« Reply #7 on: May 15, 2010, 11:11:39 PM »

This threw me off too.. Wink

window.foo tests the existence window.foo() actually calls
the function.



Code:
<html>
<script language="javascript" type="text/javascript">

function foo() {
return false;
}


if(window.foo()) {
  document.writeln('foo returned true <br />');
}
else {
  document.writeln('foo returned not true<br />');
}


if(window.foo) {
  document.writeln('foo exists <br />');
}
else {
  document.writeln('foo does not exist<br />');
}


if(window.bar) {
  document.writeln('bar exists <br />');
}
else {
  document.writeln('bar does not exist.. not in some places in texas anyway<br />');
}



</script>
</html>

Logged

When I was your age we used to walk to the TV to change the channel....  _̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 9792



View Profile
« Reply #8 on: May 15, 2010, 11:49:15 PM »

If you add parens like u did it executes. Try without parens.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« Reply #9 on: May 16, 2010, 12:27:05 PM »

thanks!

this is really cool.... same thing we do every night, TRY TO RULE THE WORLD!

Code:
$.getScript(url,callback) Load and execute a remote JavaScript file
Logged

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« Reply #10 on: May 18, 2010, 05:52:24 AM »

stay tuned....



* pinky_brain.jpg (32.1 KB, 460x349 - viewed 167 times.)
Logged

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!