igstudders Posted July 4, 2017 Share Posted July 4, 2017 I am attempting to use a meta tag to redirect someone if they attempt to go to a specified number of pages. Problem is these pages are pdf files so I cant really add some code to that. Anyway I decided to use a javascript file and import React and ReactDOM from the JS Library. I simply don't know what I am doing wrong with this code though. If anyone could help that would be amazing! import React from 'react'; import ReactDOM from 'react-dom'; String[] Directory = {"A", "Bunch", "Of", "Website", "Directories", "Here"}; if (window.location.href = "Website name here" + Directory)) { ReactDOM.render( <META http-equiv="refresh" content="0;URL=Index.html">, document.getElementById('app') ); }; Much Appreciated to whoever can help! Link to comment Share on other sites More sharing options...
Ingolme Posted July 4, 2017 Share Posted July 4, 2017 This does not appear to be browser Javascript, which does not support import statements or typed arrays. It seems like there would be an issue in your render() call because your string is not quoted. ReactDOM.render( '<META http-equiv="refresh" content="0;URL=Index.html">', // Added quotes to the string document.getElementById('app') ); Link to comment Share on other sites More sharing options...
justsomeguy Posted July 5, 2017 Share Posted July 5, 2017 Quote It seems like there would be an issue in your render() call because your string is not quoted. Welcome to ReactJS, a Javascript library designed to look completely wrong to existing Javascript programmers. Because of that, and since I'm not familiar enough with ReactJS, I don't know if these lines are correct: Quote String[] Directory = {"A", "Bunch", "Of", "Website", "Directories", "Here"}; if (window.location.href = "Website name here" + Director Should that be "==" instead of "="? If an array is concatenated on the end of a string, is that trying to test each array element or is it going to join them? Is the default to join them with slashes to produce a directory structure? I don't know how the developers of Reach chose to answer those. Link to comment Share on other sites More sharing options...
Ingolme Posted July 6, 2017 Share Posted July 6, 2017 This is unfamiliar to me, since other Javascript frameworks and libraries I've worked with did not actually alter Javascript syntax. If this really is a browser-side library, it seems pretty inefficient to parse all that code just to have a prettier syntax. It would have to be compiled into real Javascript, either using a server-side compiler or during runtime with a Javascript program. Link to comment Share on other sites More sharing options...
thescientist Posted July 6, 2017 Share Posted July 6, 2017 I would agree with a couple things mentioned The syntax is not correct (regardless of React usage) The need for React is not apparent That said, it certainly could be done with React, or "vanilla" JS would certainly be more practical as this "simple" case seems warrants. As far as implementation details go, would a better option be to increment a counter each time a link / page is visited in a cookie or with one of the web storage APIs? Either way a user can work around it, but at least one is a more "stateful" solution. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now