Cookies op Tweakers

Tweakers maakt gebruik van cookies, onder andere om de website te analyseren, het gebruiksgemak te vergroten en advertenties te tonen. Door gebruik te maken van deze website, of door op 'Ga verder' te klikken, geef je toestemming voor het gebruik van cookies. Wil je meer informatie over cookies en hoe ze worden gebruikt, bekijk dan ons cookiebeleid.

Meer informatie
Toon posts:

JS: Function not working

Pagina: 1
Acties:
  • 238 views

  • doenietzodom
  • Registratie: maart 2011
  • Laatst online: 23-01-2018
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.

For every complex problem there is an answer that is clear, simple, and wrong.


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

  • RobIII
  • Registratie: december 2001
  • Laatst online: 23:19

RobIII

Admin Devschuur®

^ Romeinse Ⅲ ja!

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.

Roses are red Violets are blue, Unexpected ‘{‘ on line 32.

Over mij


Dit topic is gesloten.



Apple iPhone 12 Microsoft Xbox Series X LG CX Google Pixel 4a CES 2020 Samsung Galaxy S20 4G Sony PlayStation 5 Nintendo Switch Lite

'14 '15 '16 '17 2018

Tweakers vormt samen met Hardware Info, AutoTrack, Gaspedaal.nl, Nationale Vacaturebank, Intermediair en Independer DPG Online Services B.V.
Alle rechten voorbehouden © 1998 - 2020 Hosting door True