Javascript 将多个JS文件合并为一个
我在很多页面上都有一个URL重定向JS代码,例如Mon.html、Tue.html等,我想将其合并成一个文件,并且根据用户的屏幕宽度将其重定向到页面的移动版本,例如Javascript 将多个JS文件合并为一个,javascript,jquery,Javascript,Jquery,我在很多页面上都有一个URL重定向JS代码,例如Mon.html、Tue.html等,我想将其合并成一个文件,并且根据用户的屏幕宽度将其重定向到页面的移动版本,例如 if(screen.width您可以将当前位置映射到重定向 if(screen.width <= 800) { switch(window.location) { case firstLocation: window.location = firstRedirect;
if(screen.width您可以将当前位置映射到重定向
if(screen.width <= 800) {
switch(window.location) {
case firstLocation:
window.location = firstRedirect;
case secondLocation:
window.location = secondRedirect;
// other redirect cases
default:
throw new Error('no redirect assigned to current location');
}
}
if(screen.width算出了
var screen\u width=screen.width;
$(函数(){
如果($('body')。是('index')&&(屏幕宽度我对你的目标感到困惑-为什么你要同时将一个用户重定向到3个不同的页面?你在所有的重读中都有相同的条件。如果你不添加任何其他条件来分隔,你就无法避免多个重读。我想你需要根据屏幕宽度和多个If-else进行一次检查n当天而不是今天?请注意,如果重定向目标页中有相同的脚本,则无需额外检查,您将有一个循环重定向。有趣的是,我如何引用“firstLocation”?
if (screen.width <= 800) {
window.location = '../m/' + window.location;
}