Toon posts:

JS: Function not working

Pagina: 1
Acties:
  • 308 views

Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
For some weird reason my function isn't working and I was wondering what im missing, I'll try to explain.

When you first load the website it needs to load a function, after this it will start loading into divs.

Code in my div (Also tried: body onload or in the header)

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<script type="text/javascript">
<?php  
if(empty($write_page['1'])) { 
?>
loadthisframe(home);
<?php 
}             
else         
{ 
?>
var <?php echo $write_page['1']; ?>;
loadthisframe(<?php echo $write_page['1']; ?>);
<?php
} 
?>
</script>


So i stripped down the complete function to test:

code:
1
2
3
function loadthisframe(loadthisframe) {
    console.log("load page");
}


The code above will display something like:
code:
1
2
3
<script type="text/javascript">
loadthisframe(home);
</script>


or

code:
1
2
3
4
<script type="text/javascript">
var contact;
loadthisframe(contact);
</script>



This is based on what page you are at,


But it doesn't work, when I delete the "var <?php echo $write_page['1']; ?>;"

I get the following: "ReferenceError: home is not defined"

The rest of the website works fine, its not that its waiting for jquery or so..


When i click on a existing tab, which does the same (kinda), works fine.

code:
1
2
3
4
5
$('#tabhome').bind('click', function(event) {
var home = "home";  
loadpageframe(home);
window.history.pushState("object or string", "Title", "/");
});


I also tried replacing loadthisframe with loadpageframe but there is where the problem started so i'm trying to strip down till i find the issue.

Acties:
  • 0 Henk 'm!

  • HamuNaptra
  • Registratie: April 2002
  • Niet online
Can you reproduce the issue in a codepen?

Acties:
  • 0 Henk 'm!

  • RobIII
  • Registratie: December 2001
  • Niet online

RobIII

Admin Devschuur®

^ Romeinse Ⅲ ja!

(overleden)
Can you create a new topic in Dutch?

There are only two hard problems in distributed systems: 2. Exactly-once delivery 1. Guaranteed order of messages 2. Exactly-once delivery.

Je eigen tweaker.me redirect

Over mij


Dit topic is gesloten.